package aspects;
 
import java.beans.PropertyChangeSupport;
import validator.ValidadorStringNoVacio;

import interfaces.*; 
import annotations.*;
public aspect validarStringsPorMixims {
	
	declare parents : @Validable * implements ObjetoValidableSupport;

	pointcut setter(ObjetoValidableSupport target, Object newValue): set(String clases..*) && args(newValue)&& target(target);
	
	void around(ObjetoValidableSupport target, Object newValue): setter(target,newValue){
		String fieldName = thisJoinPoint.getSignature().getName();
		target.fieldChanged(fieldName, newValue);
		proceed(target, newValue);
	}
	
	
	
	
	after(ObjetoValidableSupport target) : initialization(* ..*.new(..) ) && target(target) {
		target.initialize();
	}
	
	private transient PropertyChangeSupport ObjectoValidable.changeSupport;
	
	public void ObjectoValidable.initialize() {
		this.changeSupport = new PropertyChangeSupport(this);
	}
	
	public void ObjectoValidable.agregarValidador(String propertyName, ValidadorStringNoVacio listener) {
		this.changeSupport.addPropertyChangeListener(propertyName, listener);
	}
	
	public void ObjectoValidable.quitarValidador(String propertyName, ValidadorStringNoVacio listener) {
		this.changeSupport.removePropertyChangeListener(propertyName, listener);
	}
	
	
	public void ObjectoValidable.fieldChanged(String fieldType, Object newValue) {
		this.changeSupport.firePropertyChange(fieldType,"nada" ,newValue);
	}
}
